package com.liyong.pullorder.sdk.exception;

/**
 * @author 葡萄味的萝卜
 * @date 2025/10/21 13:08
 * 数据解析异常
 * 核心作用：标识数据解析过程中的错误
 * 触发场景：JSON/XML解析失败、字段映射错误、数据格式不符
 * 处理策略：部分可重试，记录原始数据用于排查
 */
public class DataParseException extends PullOrderException{
    private final String rawData;

    public DataParseException(String message) {
        super(message, "DATA_PARSE_ERROR", "UNKNOWN");
        this.rawData = null;
    }

    public DataParseException(String message, String platformCode) {
        super(message, "DATA_PARSE_ERROR", platformCode);
        this.rawData = null;
    }

    public DataParseException(String message, Throwable cause, String platformCode) {
        super(message, cause, "DATA_PARSE_ERROR", platformCode);
        this.rawData = null;
    }

    public DataParseException(String message, Throwable cause, String platformCode, String rawData) {
        super(message, cause, "DATA_PARSE_ERROR", platformCode);
        this.rawData = rawData;
    }

    public String getRawData() {
        return rawData;
    }

    /**
     * 获取脱敏的原始数据（用于日志记录）
     */
    public String getMaskedRawData() {
        if (rawData == null) {return null;}
        if (rawData.length() <= 100) {return rawData;}
        return rawData.substring(0, 50) + "..." + rawData.substring(rawData.length() - 50);
    }
}
